package com.example.webservice_s;

import org.apache.cxf.Bus;
import org.apache.cxf.bus.spring.SpringBus;
import org.apache.cxf.jaxws.EndpointImpl;
import org.apache.cxf.transport.servlet.CXFServlet;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.xml.ws.Endpoint;


/**
 * Created with IntelliJ IDEA.
 *
 * @Author: ZhangLiang
 * @Date: 2021/07/10/14:31
 * @Description: 配置类
 */
@Configuration
public class WebConfig {

    @Bean
    public ServletRegistrationBean wsServlet(){
        return new ServletRegistrationBean(new CXFServlet(), "/ws/*");
    }
    @Autowired
    @Qualifier(Bus.DEFAULT_BUS_ID)
    private SpringBus bus;

    @Autowired
    InvoiceWebService invoiceWebService;

    @Bean
    public Endpoint invoiceEndpoint(){
        EndpointImpl endpoint = new EndpointImpl(bus,invoiceWebService);
        System.out.println("---------接口发布开始----------");
        endpoint.publish("/testApiService");
        System.out.println("----------接口发布成功-----------");
        return endpoint;
    }
}
